package fr.louloutes.lolshooter;

import android.util.Log;

public class LolLog
{
	public static final String ROOT_TAG = "LOLShooter";
	public static final LolLog ROOT_LOG = new LolLog( null, null );

	public static LolLog getRoot()
	{
		return ROOT_LOG;
	}

	// static methods for root logging

	public static void rv( String msg )
	{
		Log.v( ROOT_TAG, msg );
	}

	public static void rv( String msg, Throwable tr )
	{
		Log.v( ROOT_TAG, msg, tr );
	}

	public static void rd( String msg )
	{
		Log.d( ROOT_TAG, msg );
	}

	public static void rd( String msg, Throwable tr )
	{
		Log.d( ROOT_TAG, msg, tr );
	}

	public static void ri( String msg )
	{
		Log.i( ROOT_TAG, msg );
	}

	public static void ri( String msg, Throwable tr )
	{
		Log.i( ROOT_TAG, msg, tr );
	}

	public static void rw( String msg )
	{
		Log.w( ROOT_TAG, msg );
	}

	public static void rw( Throwable tr )
	{
		Log.w( ROOT_TAG, tr );
	}

	public static void rw( String msg, Throwable tr )
	{
		Log.w( ROOT_TAG, msg, tr );
	}

	public static void re( String msg )
	{
		Log.e( ROOT_TAG, msg );
	}

	public static void re( String msg, Throwable tr )
	{
		Log.e( ROOT_TAG, msg, tr );
	}

	public static void rwtf( String msg )
	{
		Log.wtf( ROOT_TAG, msg );
	}

	public static void rwtf( Throwable tr )
	{
		Log.wtf( ROOT_TAG, tr );
	}

	public static void rwtf( String msg, Throwable tr )
	{
		Log.wtf( ROOT_TAG, msg, tr );
	}

	// one utility function
	public static String getStackTraceString( Throwable tr )
	{
		return Log.getStackTraceString( tr );
	}

	private final LolLog parentLog;
	private final String localTag;

	private LolLog( LolLog parent, String localTag )
	{
		this.parentLog = parent;
		if ( this.parentLog == null )
		{
			this.localTag = ROOT_TAG;
		} else
		{
			if ( !"".equals( localTag ) && localTag != null )
			{
				this.localTag = localTag;
			} else
			{
				this.localTag = "no_tag";
			}
		}
	}

	public LolLog getSubLogger( String subTag )
	{
		return new LolLog( this, subTag );
	}

	// member methods for sub logging

	public void v( String msg )
	{
		Log.v( localTag, msg );
		if ( parentLog != null )
		{
			parentLog.v( msg );
		}
	}

	public void v( String msg, Throwable tr )
	{
		Log.v( localTag, msg, tr );
		if ( parentLog != null )
		{
			parentLog.v( msg, tr );
		}
	}

	public void d( String msg )
	{
		Log.d( localTag, msg );
		if ( parentLog != null )
		{
			parentLog.d( msg );
		}
	}

	public void d( String msg, Throwable tr )
	{
		Log.d( localTag, msg, tr );
		if ( parentLog != null )
		{
			parentLog.d( msg, tr );
		}
	}

	public void i( String msg )
	{
		Log.i( localTag, msg );
		if ( parentLog != null )
		{
			parentLog.i( msg );
		}
	}

	public void i( String msg, Throwable tr )
	{
		Log.i( ROOT_TAG, msg, tr );
		if ( parentLog != null )
		{
			parentLog.i( msg, tr );
		}
	}

	public void w( String msg )
	{
		Log.w( ROOT_TAG, msg );
		if ( parentLog != null )
		{
			parentLog.w( msg );
		}
	}

	public void w( Throwable tr )
	{
		Log.w( ROOT_TAG, tr );
		if ( parentLog != null )
		{
			parentLog.w( tr );
		}
	}

	public void w( String msg, Throwable tr )
	{
		Log.w( ROOT_TAG, msg, tr );
		if ( parentLog != null )
		{
			parentLog.w( msg, tr );
		}
	}

	public void e( String msg )
	{
		Log.e( ROOT_TAG, msg );
		if ( parentLog != null )
		{
			parentLog.e( msg );
		}
	}

	public void e( String msg, Throwable tr )
	{
		Log.e( ROOT_TAG, msg, tr );
		if ( parentLog != null )
		{
			parentLog.e( msg, tr );
		}
	}

	public void wtf( String msg )
	{
		Log.wtf( ROOT_TAG, msg );
		if ( parentLog != null )
		{
			parentLog.wtf( msg );
		}
	}

	public void wtf( Throwable tr )
	{
		Log.wtf( ROOT_TAG, tr );
		if ( parentLog != null )
		{
			parentLog.wtf( tr );
		}
	}

	public void wtf( String msg, Throwable tr )
	{
		Log.wtf( ROOT_TAG, msg, tr );
		if ( parentLog != null )
		{
			parentLog.wtf( msg, tr );
		}
	}

}
